<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
 * This file is part of KReporter. KReporter is an enhancement developed 
 * by KINAMU Business Solutions AG. All rights ar (c) 2010 by KINAMU Business
 * Solutions AG.
 *
 * KReporter is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * KReporter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KReporter.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * You can contact KINAMU Business Solutions AG at Am Concordepark 2/F12
 * A-2320 Schwechat or via email at office@kinamu.com
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the Name KINAMU in the Name
 * of the Module which needs to be visible to the User.
 * 
 ********************************************************************************/
require_once('include/MVC/View/views/view.detail.php');
require_once('include/utils.php');
require_once('modules/KReports/utils.php');

class KReportsViewDetail extends ViewDetail {

 	function KReportsViewDetail(){
 		parent::ViewDetail();
 	}
 	
 	function json_decode_kinamu($json)
	{ 
	    	    $comment = false;
	    $out = '$x=';
	   
	    for ($i=0; $i<strlen($json); $i++)
	    {
	        if (!$comment)
	        {
	            if ($json[$i] == '{' or $json[$i] == '[')        $out .= ' array(';
	            else if ($json[$i] == '}' or $json[$i] == ']')    $out .= ')';
	            else if ($json[$i] == ':')    $out .= '=>';
	            else                         $out .= $json[$i];           
	        }
	        else $out .= $json[$i];
	        if ($json[$i] == '"')    $comment = !$comment;
	    }
	    eval($out . ';');
	    return $x;
	}  
	
	 function display() {

        global $app_list_stings, $mod_strings, $current_language;
		
        		$mod_lang = return_module_language($current_language, 'KReports');
		
		foreach($mod_lang as $id => $value)
		{
			$returnArray[] = array('lblid' => $id, 'value' => $value);
		}
		
		$this->ss->assign('jsonlanguage', json_encode_kinamu($returnArray));	 		
	 		
 		 		$arrayList =  $this->json_decode_kinamu( html_entity_decode_utf8($this->bean->listfields));
 		$fieldArray  = '';
 		
 		foreach($arrayList as $thisList){
 			$fieldArray .= ($fieldArray == '') ? '[' : ',';
 			$fieldArray .= '{name : \'' . trim($thisList['fieldid'], ':') . '\'}';
 		}	
       	      	$fieldArray .= "]";
 		$this->ss->assign('listfieldarray', $fieldArray);
      	
 		
 		 		reset($arrayList);
 		
 		$columnModelArray = '';
 		foreach($arrayList as $thisList){
 			if($thisList['display'] == 'yes')
 			{
 				$columnModelArray .= ($columnModelArray == '') ? '[' : ',';
 				$columnModelArray .= '{header : \'' . trim($thisList['name'], ':') . '\', width: ' . ((isset($thisList['width']) && $thisList['width'] != '' && $thisList['width'] != '0') ? $thisList['width'] : '150') .', sortable: true, dataIndex: \'' . trim($thisList['fieldid'], ':') . ((isset($thisList['sqlfunction']) && $thisList['sqlfunction'] != '-' ) ? '\', summaryType:\'' . $thisList['sqlfunction'] : '') . '\'}';
 			}
 		}
 		
 		 		$columnModelArray .= "]";

 		$this->ss->assign('columnmodeldarray', $columnModelArray);
 		
 		 		$whereFieldsList =  $this->json_decode_kinamu( html_entity_decode_utf8($this->bean->whereconditions));
 		
 		foreach($whereFieldsList as $whereFieldKey =>$whereField)
 		{
 			if($whereField['usereditable'] == 'yes')
 			{
 				$editableWhereFields[] = $whereField;
 			}
 		}

 	
 		$jsonWhereOptions = str_replace("\"", "'", json_encode_kinamu($editableWhereFields));
 		if(count($editableWhereFields) > 0)
 			$this->ss->assign('dynamicoptions', $jsonWhereOptions);
 		else
 			$this->ss->assign('dynamicoptions', '');
 			

 		$this->ss->assign('haschart', 'N');

		parent::display();
 	}
	
}
?>
